<?php



require 'php-sdk/src/facebook.php';


// Create our Application instance (replace this with your appId and secret).
$facebook = new Facebook(array(
  'appId'  => '176213615761250',
  'secret' => '375110a154f2a4f5b2f6e4f8f093f7be',
));

// Get User ID
$user = $facebook->getUser();



if ($user) {
	try {
		// Proceed knowing you have a logged in user who's authenticated.
		$user_profile = $facebook->api('/me');
		$friends = $facebook->api('/me/friends');
		foreach ($friends as $key=>$value) {
			$x = count($value);
		}
		for ($i=0 ; $i<5 ; $i++) {
			$random=rand(0, $x);
			echo '<a href="http://www.facebook.com/' . $friends['data'][$random]['id'] . '" target="_blank"/><img src="https://graph.facebook.com/' . $friends['data'][$random]['id'] . '/picture" align= "middle" title="' . $friends['data'][$random]['name'] . '"/>' . $friends['data'][$random]['name'] . '<br><br></a>';
		}
	} catch (FacebookApiException $e) {
		error_log($e);
		$user = null;
		echo "An error occured! Try again!<br><br> $e";
	}
}
else {
	$loginUrl = $facebook->getLoginUrl();
	echo "<a href=" . $loginUrl . ">Login with Facebook</a>";
}

?>
